//
// Build
//
// Copyright (C) jextra.net.
//
//  This file is part of the Crack build system.
//
//  The Crack build system is free software; you can redistribute it 
//  and/or modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  The Crack build system is distributed in the hope that it will be 
//  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with the Crack build system; if not, write to the Free
//  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
//  02111-1307 USA.
//

package net.jextra.crack.test;

import java.io.*;
import net.jextra.crack.*;
import net.jextra.crack.tool.*;
import net.jextra.crack.type.*;

public class Build extends CrackBuild
{
    // ============================================================
    // Fields
    // ============================================================

    private File rootDir = new File( "../../../../.." );
    private File srcDir = new File( rootDir, "src" );
    private File classesDir = new File( rootDir, "classes" );
    private File docsDir = new File( rootDir, "docs" );
    private File buildDir = new File( rootDir, "build" );

    private String packagePrefix = "net/jextra/crack/test/";
    private RegexFileStrainer selfStrainer = new RegexFileStrainer().exclude( "Build\\.java" );
    private FileSet srcFiles = new StrainedFileSet( srcDir, selfStrainer );

    // ============================================================
    // Methods
    // ============================================================

    // ----------
    // public
    // ----------

    @CrackCommand
    public void clean()
        throws IOException
    {
        FileTool.cleanDir( new File( classesDir, packagePrefix ) );
    }

    @CrackCommand
    public void compile()
        throws IOException
    {
        classesDir.mkdirs();

        JavaCompiler compiler = new JavaCompiler();
        compiler.addSourceDir( srcDir );
        compiler.setOutputDir( classesDir );
//        compiler.compile( _selfStrainer );
    }

    @CrackCommand
    public void build()
        throws Exception
    {
        invokeCommand( "compile" );

        buildDir.mkdirs();
    }

    @CrackCommand
    public void javadoc()
    {
        docsDir.mkdirs();

        JavadocTool javadoc = new JavadocTool();
        javadoc.setOutputDir( docsDir );
        javadoc.execute( srcFiles );
    }

    @CrackCommand
    public void shrinkwrap()
        throws Exception
    {
        invokeCommand( "compile" );
        invokeCommand( "build" );
    }
}

